package com.cto.uaa.single;

/**
 * @description: 普通的单例模式
 * 1.没有用到懒加载
 * 2.构造函数私有化
 * @author: qiu
 * @param:
 * @create: 2022-01-09
 **/
public class Single01 {
    private Single01(){}

    private static Single01 instance = new Single01();

    public Single01 getInstance(){
        return instance;
    }

/**
 * @description: 懒加载的单例模式
 * 2.构造函数私有化
 * @author: qiu
 * @param:
 * @create: 2022-01-09
 **/
class Single02 {
    private Single02(){}

    private Single02 instance ;

    public Single02 getInstance(){
        if (instance!=null){
            instance = new Single02();
        }
        return instance;
    }
}

/**
 * @description: 双重校验锁的单例模式
 * 2.构造函数私有化
 * @author: qiu
 * @param:
 * @create: 2022-01-09
 **/
class Single03 {
    private Single03(){}

    private volatile Single03 instance ;

    public Single03 getInstance(){
        if (instance!=null){
            synchronized (instance){
                if (instance==null){
                    instance = new Single03();
                }
            }
        }
        return instance;
    }
}

}
